<template>
  <!-- 医生就诊历史记录 -->
  <section>
    <div class="form-tool">
      <div>
        <el-form :inline="true" @submit.native.prevent="getData(-1)">
          <el-form-item>
            <el-select v-model="form.deptId" placeholder="请选择科室" @change="onChangeDept">
              <el-option
                v-for="(item,index) in doctorInfo.depts"
                :key="index"
                :label="item.deptName"
                :value="item.deptId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <doctorSearch
              ref="doctorSearch"
              v-model="form.doctorId"
              :deptId="form.deptId"
              :pageSize="100"
            ></doctorSearch>
          </el-form-item>
          <el-form-item>
            <el-date-picker
              v-model="form.receptionTimeStart"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="开始日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-date-picker
              v-model="form.receptionTimeEnd"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <!-- <el-input v-model="form.nameOrMobile" placeholder="请输入姓名或手机号"></el-input> -->
            <patientSearch v-model="form.patientId"></patientSearch>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" native-type="submit" circle></el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <el-row :gutter="20">
      <el-col
        v-for="(item,index) in tableList"
        :key="index"
        :xs="12"
        :sm="12"
        :md="12"
        :lg="8"
        :xl="6"
        class="reserve-user-list"
      >
        <!-- vip-box  -->
        <div :class="['card-box',classToName(item.status) ]">
          <div class="card-nr">
            <div>
              <img
                v-if="!item.patientInfo.head"
                src="@/img/unknown-avatar.png"
                class="head-img"
                alt
                style="width:70px;height:70px;"
              />
              <img
                v-else
                :src="item.patientInfo.head|imageUrl"
                class="head-img"
                alt
                style="width:70px;height:70px;"
              />
            </div>
            <div style="overflow: hidden;">
              <p class="overflow-omit">
                <span style="font-size:18px;">{{item.patientInfo.name}}</span>
                &nbsp;
                <span>
                  （{{item.patientInfo.sex|toSex}}&nbsp;
                  <span
                    v-if="item.patientInfo.age>17"
                  >{{item.patientInfo.age}}岁</span>
                  <span v-else>{{item.patientInfo.birthday|toTimeContrast}}</span>）
                </span>
              </p>
              <div class="overflow-omit">手机号：{{item.patientInfo.mobile}}</div>
              <div class="overflow-omit">就诊时间：{{item.receptionTime}}</div>
              <div class="overflow-omit">诊断：{{item.patientSimpleInfoDetailResponse.firstVisitInfo}}</div>
            </div>
          </div>
          <div class="card-footer">
            <!-- <div @click="onJieZhen(item)">接诊</div> -->
            <div @click="onPatDetail(item)">患者信息</div>
            <div @click="onReport(item)">查看报告</div>
            <!-- <div @click="onClickYY(item)">预约</div> -->
            <div>
              <el-dropdown
                trigger="click"
                style="width:100%;"
                @command="onMoreOperations($event,item)"
              >
                <div>更多操作</div>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="3">
                    <i class="el-icon-edit-outline vertical-middle"></i>
                    <span class="vertical-middle">修改病历</span>
                  </el-dropdown-item>
                  <el-dropdown-item command="1">
                    <i class="el-icon-s-custom vertical-middle"></i>
                    <span class="vertical-middle">完善信息</span>
                  </el-dropdown-item>
                  <el-dropdown-item command="2">
                    <i class="el-icon-document vertical-middle"></i>
                    <span class="vertical-middle">预约</span>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </div>
          <!-- <div class="zt-box">{{item.status|changeAssist(reserveTypeArray)}}</div> -->
          <div v-if="item.patientInfo.levelId" class="vip-box">
            <el-tooltip :content="item.patientInfo.levelName" placement="top">
              <img src="@/img/icon-vip.png" alt />
            </el-tooltip>
          </div>
        </div>
      </el-col>
    </el-row>
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br />
    <pager v-model="pager" @change-pagenum="getData"></pager>
    <dialogWriteData v-model="dialogWriteData" :patientId="curItem.patientInfo.patientId"></dialogWriteData>
    <dialog-report
      v-model="dialogReport"
      :cureId="curItem.cureId"
      :patientId="curItem.patientInfo.patientId"
    ></dialog-report>
    <caseUpdate
      v-model="dialogCaseUpdate"
      :cureId="curItem.cureId"
      :doctorId="curItem.doctorId"
      :deptId="curItem.deptId"
    ></caseUpdate>
  </section>
</template>
<script>
export default {
  props: ["doctorInfo"],
  components: {
    patientSearch: () => import("@/pages/_com/patientSearch.vue"),
    dialogWriteData: () => import("@/pages/_com/dialogWriteData.vue"),
    dialogReport: () => import("./dialogReport.vue"),
    caseUpdate: () => import("./caseUpdate.vue"),
    doctorSearch: () => import("@/pages/_com/doctorSearch.vue")
  },
  data() {
    return {
      dialogCaseUpdate: false,
      dialogReport: false,
      dialogWriteData: false,
      curItem: {
        patientInfo: {
          patientId: ""
        }
      },
      form: {
        status: "2,5,6",
        doctorId: "",
        deptId: null,
        receptionTimeStart: "",
        receptionTimeEnd: "",
        patientId: "",
        isHistory: 1
      },
      tableList: [],
      reserveTypeArray: [],
      pager: { pageSize: 12, pageNum: 1, total: 0 }
    };
  },
  created() {
    const th = this;
    th.form.deptId = th.doctorInfo.depts[0].deptId;
    th.form.doctorId = th.doctorInfo.id;
  },
  async mounted() {
    let th = this;
    let date = new Date();
    //获取当前日期
    let nowDate = th.$utils.FormatTime("yyyy-MM-dd", date.getTime());
    //计算往前30天的日期
    let oldDate = date.setDate(date.getDate() - 30);
    oldDate = new Date(oldDate);
    //格式化往前30天的日期
    let pasDate = th.$utils.FormatTime("yyyy-MM-dd", oldDate.getTime());
    //日期组件赋值
    th.form.receptionTimeStart = pasDate;
    th.form.receptionTimeEnd = nowDate;
    th.showLoading();
    th.reserveTypeArray = await th.getCommonConfigByKey("预约类型");
    th.getData(-1);
  },
  methods: {
    //接诊
    onJieZhen(obj) {
      let th = this;
      let j = {
        patientId: obj.patientInfo.patientId,
        doctorId: obj.doctorId,
        deptId: obj.deptId,
        registerId: obj.id,
        isFirstVisit: obj.registerType,
        id: obj.cureId ? obj.cureId : null
      };
      th.showLoading();
      th.$api.doctorJieZhen(j).then(res => {
        th.showLoading(false);
        if (res.executed) {
          let url = "/page/jieZhen";
          th.$router.push({
            path: url,
            query: th.getUrlToken({
              patientId: th.jiaMi(obj.patientInfo.patientId),
              cureId: th.jiaMi(obj.cureId ? obj.cureId : res.data),
              deptId: th.jiaMi(obj.deptId),
              doctorId: th.jiaMi(obj.doctorId),
              isNew: j.id ? false : true,
              deptName: obj.deptName,
              doctorName: th.doctorInfo.trueName
            })
          });
        } else {
          th.$message.error(res.message);
        }
      });
    },
    //查看报告
    onReport(obj) {
      const th = this;
      if (!obj.cureId) {
        th.$message.warning("该患者还未有就诊记录");
        return;
      }
      th.curItem = obj;
      th.dialogReport = true;
    },
    //完善信息
    onPerfectData(obj) {
      const th = this;
      th.curItem = obj;
      th.dialogWriteData = true;
    },
    getData(type) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      th.showLoading();
      let j = {};
      Object.assign(j, th.form, th.pager);
      th.$api.getRegisterListInfo(j).then(res => {
        if (res.executed) {
          th.tableList = res.dataBody.list;
          th.pager.total = res.dataBody.total;
        }
        th.showLoading(false);
      });
    },
    //预约
    onClickYY(obj) {
      let th = this;
      let url = "/page/reservecentre";
      //验证页面权限
      if (!th.verifyUrl(url)) {
        th.$message.warning("权限不足");
        return;
      }
      th.delCache("reservecentre");
      //修改预约
      th.addNavMenu("预约", url, "reservecentre");
      th.$router.push({
        path: "/page/reservecentre",
        query: th.getUrlToken({
          patientId: th.jiaMi(obj.patientInfo.patientId),
          name: obj.patientInfo.name,
          yyId: th.jiaMi(obj.id)
        })
      });
    },
    //病人详细
    onPatDetail(obj) {
      const th = this;
      let url = "/page/userDetail";
      let j = th.getUrlToken({
        id: th.jiaMi(obj.patientInfo.patientId)
      });
      th.addNavMenu("病人库", url + th.$utils.JsonToUrl(j),'userDetail');
      th.$router.push({
        path: url,
        query: j
      });
    },
    //更多操作
    onMoreOperations(key, obj) {
      let th = this;
      switch (key) {
        case "1":
          th.onPerfectData(obj);
          break;
        case "2":
          th.onClickYY(obj);
          break;
        case "3":
          //修改病历
          th.curItem = obj;
          th.dialogCaseUpdate = true;
          break;
        case "4":
          break;
      }
    },
    //判断类名
    classToName(type) {
      switch (type) {
        case 1:
          return "bg-yjz";
          break;
        case 2:
          return "bg-sy";
          break;
        case 3:
          return "bg-hong";
          break;
        case 4:
          return "bg-yqx";
          break;
        case 5:
          return "bg-jzz";
          break;
        default:
          return "bg-dfz";
          break;
      }
    },
    //选择科室
    onChangeDept() {
      const th = this;
      th.$refs["doctorSearch"].getSearch();
    }
  }
};
</script>
<style lang="scss" scoped>
@import "../../_css/reserve.scss";
</style>
